.TH std::counted_iterator::count 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::counted_iterator::count \- std::counted_iterator::count

.SH Synopsis
   constexpr std::iter_difference_t<I> count() const noexcept;  \fI(since C++20)\fP

   Returns the underlying length that is the distance to the end.

.SH Parameters

   \fI(none)\fP

.SH Return value

   The underlying length.

.SH Example


// Run this code

 #include <cassert>
 #include <iostream>
 #include <iterator>

 int main()
 {
     constexpr static auto il = {1, 2, 3, 4, 5};
     constexpr std::counted_iterator i1{il.begin() + 1, 3};
     static_assert(i1.count() == 3);
     auto i2{i1};
     for (; std::default_sentinel != i2; ++i2)
         std::cout << "*i2: " << *i2 << ", count(): " << i2.count() << '\\n';
     assert(i2.count() == 0);
 }

.SH Output:

 *i2: 2, count(): 3
 *i2: 3, count(): 2
 *i2: 4, count(): 1

.SH See also

   base    accesses the underlying iterator
   (C++20) \fI(public member function)\fP
